package fr.mbds.first.wallet.Activity;

import java.util.Map;

import org.mbds.wolf.seql.ISeqlCallBack;
import org.mbds.wolf.seql.ISeqlController;
import org.mbds.wolf.seql.SeqlController;
import org.mbds.wolf.seql.exceptions.APDUError;

import fr.mbds.first.wallet.service.ServiceFirst;

import android.app.Application;
import android.nfc.cardemulation.HostApduService;
import android.widget.Toast;

public class DebitCreditFirstAppli extends Application implements ISeqlCallBack{

	private static ISeqlController ctrl = null;
	
	@Override
	public void onCreate(){
		super.onCreate();
		init();
	}
	
	public ISeqlController getController(){
		return ctrl;
	}
	
	public void init(){
		
		boolean ok = false;
		
		try{
			SeqlController.CONFIG os = SeqlController.CONFIG.ANDROID_HCE;
			System.out.println("SDK = " + android.os.Build.VERSION.SDK_INT);
//			if(android.os.Build.VERSION.SDK_INT < 19)
//				os = SeqlController.CONFIG.ANDROID_OMAPI;
			
			ctrl = SeqlController.getController(getApplicationContext(), os, this, ServiceFirst.class.getName());
			ctrl.initService();

			ok = true;
		
		}catch(Exception e){
			e.printStackTrace();
		}
		
		if(!ok){
			System.out.println("SE-QL controller could note be instantiated, application will finish!");
			Toast.makeText(this, "SE-QL controller could note be instantiated, application will finish!",  Toast.LENGTH_LONG).show();
			quitApp();
		}
		else System.out.println("appli");
	}
	
	public void quitApp(){
		System.out.println("exit");
		System.exit(0);
	}
	
	@Override
	public void onAPDUError(APDUError arg0) {
		System.out.println("onAPDUError");
	}

	@Override
	public void onBadRequest(String arg0) {
		System.out.println("onBadRequest");
	}

	@Override
	public void onConnected() {
		System.out.println("Connected to SE");
	}

	@Override
	public void onIOException(String arg0) {
		System.out.println("onIOException");
	}

	@Override
	public void onNoApplet() {
		System.out.println("onNoApplet");
	}

	@Override
	public void onNoReader() {
		System.out.println("onNoReader");
	}

	@Override
	public void onNoSecureElement() {
		System.out.println("onNoSecureElement");
	}

	@Override
	public void onNotConnected() {
		System.out.println("onNotConnected");
	}

	@Override
	public void onPINRequired() {
		System.out.println("onPINRequired");
	}

	@Override
	public void onConfigError() {
		System.out.println("onConfigError");
	}

	@Override
	public void onResponse(Map<String, Object> arg0, int arg1) {
		System.out.println("onResponse");
		System.out.println("arg1 = " + arg1);
	}
	

}
